fix: replace force-unwraps in host command paths - #82
Merged
Conversation
Closes #13. visual compare read its two artifact names with request.parameters[...]! .stringValue! on both hosts. That is safe only while CommandRequest.validate() has run first, and these hosts are long-lived: a trap kills the browser, every session, and any active recording, so the failure mode is out of proportion to the mistake. Both sites now guard and answer MISSING_PARAMETER. Also replaces a nil-check-then-force-unwrap in Diagnostics with a plain if-let. Same behaviour, no trap to reason about. The validator does require both parameters, so these guards are defence in depth rather than a live bug fix. ProtocolTests now asserts that requirement directly, so relaxing the validator fails a test instead of quietly making the guards load-bearing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #13.
visual compareread its two artifact names asrequest.parameters["before"]!.stringValue!on both hosts. That is safe only whileCommandRequest.validate()has run first — and these are long-lived host processes, so a trap does not fail one command, it kills the browser, every session, and any active recording.Both sites now guard and answer
MISSING_PARAMETER. Also replaced a nil-check-then-force-unwrap inDiagnostics.swiftwith a plainif let.Honest scope
This is defence in depth, not a live bug fix. The validator does require both parameters (
Protocol.swift:364-370,required: true), so no request reaching the host today can trip these unwraps. The reason to fix them anyway is the asymmetry: the cost of the guard is two lines, the cost of being wrong later is the whole host.Rather than add an unreachable test,
ProtocolTestsnow asserts the property the guards depend on — thatvisual.comparerejects a request missingbeforeorafter. If someone relaxes the validator, a test fails instead of the guards quietly becoming load-bearing.Per
AGENTS.md, remaining force-unwraps in host paths are tracked, not precedent — this clears the known set.